package com.mktneutral.etf;

/**
 * Created with IntelliJ IDEA.
 * User: JVigil0515c
 * Date: 8/16/12
 * Time: 1:44 AM
 * To change this template use File | Settings | File Templates.
 */
public class ETF implements Comparable<ETF> {
    private String ticker;
    private double ttmd;
    private double lastPrice;

    public ETF(String ticker) {
        this.ticker = ticker;
        ttmd = 0.0;
        lastPrice = 0.0;
    }

    public void incrementTTMD(double increment) {
        ttmd += increment;
    }

    public double getTTMD() {
        return ttmd;
    }

    public String getTicker() {
        return ticker;
    }

    public void processLine(String line) throws ArrayIndexOutOfBoundsException {
        String[] cols = line.split(",");

        if (cols[0].compareTo("2011-08-22") >= 0) {
            incrementTTMD(Double.parseDouble(cols[1]));
        }
    }

    public void setLastPrice(double lastPrice) {
        this.lastPrice = lastPrice;
    }

    public double getLastPrice() {
        return lastPrice;
    }

    public double getDividendYield() {
    	if ( lastPrice > 0.0 ) {
          return (ttmd / lastPrice);
    	}
    	else {
    		return 0.0;
    	}
    }
    
    public int compareTo( ETF etf ) {
    	double etfDiv = etf.getDividendYield();
    	double thisDiv = this.getDividendYield();
    	
    	if (  thisDiv > etfDiv ) {
    		return 1;
    	}
    	else if ( thisDiv < etfDiv ) {
    		return -1;
    	}
    	else {
    		return 0;
    	}
    }

	public double getTtmd() {
		return ttmd;
	}

	public void setTtmd(double ttmd) {
		this.ttmd = ttmd;
	}

	public void setTicker(String ticker) {
		this.ticker = ticker;
	}
}
